
import 'package:json_annotation/json_annotation.dart';

import '../../../utils/string_utils.dart';
import '../../../widget/w_toast.dart';

part 'leads_follow_info.g.dart';

@JsonSerializable()
class LeadsFollowInfo {

  ///线索ID
  int? clueId;
  ///跟进方式
  int? followMethod;
  ///跟进结果
  int? followResult;
  ///战败原因
  int? defeatReason;
  ///无效原因
  int? invalidReason;
  ///意向级别
  int? level;
  ///跟进记录
  @JsonKey(defaultValue: "")
  String? followRemark;
  ///下次跟进时间
  @JsonKey(defaultValue: "")
  String? nextFollowTime;
  ///邀约到店/试驾
  int? isAppointDrive;
  ///预约试驾车型
  @JsonKey(defaultValue: "")
  String? modelId;
  ///预约试驾车型名称
  @JsonKey(defaultValue: "")
  String? modelName;
  ///预约日期
  @JsonKey(defaultValue: "")
  String? appointDriveTime;
  ///预约时间段ID
  int? appointDriveResourceId;
  ///预约时间段
  @JsonKey(defaultValue: "")
  String? appointDriveTimeShow;
  ///附件
  List<Map<String, dynamic>>? filesList;

  LeadsFollowInfo({this.clueId, this.followMethod, this.followResult, this.defeatReason, this.invalidReason, this.level, this.followRemark, this.nextFollowTime, this.isAppointDrive,this.modelId, this.modelName, this.appointDriveTime, this.appointDriveResourceId, this.appointDriveTimeShow, this.filesList});

  factory LeadsFollowInfo.fromJson(Map<String, dynamic> json) => _$LeadsFollowInfoFromJson(json);

  Map<String,dynamic> toJson() => _$LeadsFollowInfoToJson(this);

  static bool check(LeadsFollowInfo info, bool isAssistance) {
    if (StringUtils.isEmpty2(info.followMethod)) {
      Toast.toast("请选择跟进方式");
      return false;
    }
    if(!isAssistance) {
      if (StringUtils.isEmpty2(info.followResult)) {
        Toast.toast("请选择跟进结果");
        return false;
      }
      if (info.followResult == 19101002 && StringUtils.isEmpty2(info.defeatReason)) {
        Toast.toast("请选择战败原因");
        return false;
      }
      if (info.followResult == 19101003 && StringUtils.isEmpty2(info.invalidReason)) {
        Toast.toast("请选择无效原因");
        return false;
      }
      if (info.followResult == 19101001 && StringUtils.isEmpty2(info.level)) {
        Toast.toast("请选择意向级别");
        return false;
      }
    }
    if (StringUtils.isEmpty2(info.followRemark)) {
      Toast.toast("请填写跟进记录");
      return false;
    }
    if (!isAssistance) {
      if (info.followResult == 19101001 && StringUtils.isEmpty2(info.nextFollowTime)) {
        Toast.toast("请选择下次跟进时间");
        return false;
      }
      if (info.isAppointDrive == 10221002 && StringUtils.isEmpty2(info.modelId)) {
        Toast.toast("请选择预约试驾车型");
        return false;
      }
      if (info.isAppointDrive != null && StringUtils.isEmpty2(info.appointDriveTime)) {
        Toast.toast("请选择预约日期");
        return false;
      }
      if (info.isAppointDrive != null && StringUtils.isEmpty2(info.appointDriveTimeShow)) {
        Toast.toast("请选择预约时间");
        return false;
      }
    }
    return true;
  }

}